package com.zhiche.lisa.mdm.controller.inner;


import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.mdm.dao.model.LocationType;
import com.zhiche.lisa.mdm.service.ILocationTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/inner/locationType")
@Api(value = "/inner/locationType", description = "地址类型接口",tags={"地址类型接口"})
public class LocationTypeController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LocationTypeController.class);

    @Autowired
    private ILocationTypeService locationTypeService;

    @GetMapping("/getLocationTypeByValue")
    @ApiOperation(value = "根据名称获取地址类型", notes = "根据名称获取地址类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<LocationType> getLocationTypeByValue(String typeValue) {
        LOGGER.info("LocationTypeController.getLocationTypeByValue（根据名称获取发卡方类型） params : {} ", typeValue);

        RestfulResponse<LocationType> result = new RestfulResponse<>(0,"success",null);
        try {
            result.setData(locationTypeService.getLocationTypeByValue(typeValue));
        } catch (BaseException e) {
            LOGGER.error("LocationTypeController.getLocationTypeByValue ERROR... ", e);
            result = new RestfulResponse<>(e.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("LocationTypeController.getLocationTypeByValue ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping("/getLocationTypeById")
    @ApiOperation(value = "根据ID获取地址类型", notes = "根据ID获取地址类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<LocationType> getLocationTypeById(Long id) {
        LOGGER.info("LocationTypeController.getLocationTypeByValue（根据名称获取发卡方类型） params : {} ", id);

        RestfulResponse<LocationType> result = new RestfulResponse<>(0,"success",null);
        try {
            LocationType locationType = locationTypeService.selectById(id);
            result.setData(locationType);
        } catch (BaseException e) {
            LOGGER.error("LocationTypeController.getLocationTypeByValue ERROR... ", e);
            result = new RestfulResponse<>(e.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("LocationTypeController.getLocationTypeByValue ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;


    }



}
